" vim: ft=vim
" Test open for reading and writing at the same time.

Before;
let file = tempname()
let content = 'this is a lower case string'
call writefile([content], file)


Execute(Read+Write);
let f = object#open(file, 'rw')
Assert f.readable() && f.writable()
AssertEqual f.read(), content

let content = toupper(content)
call f.write(content)
call f.flush()
AssertEqual readfile(file)[0], content


Execute(Read+Append);
let f = object#open(file, 'ra')
Assert f.readable() && f.writable()

call f.writeline(f.read())
call f.close()

AssertEqual readfile(file), [content, content]


Execute(Append);
" Open for appending.
let f = object#open(file, 'a')
Assert f.writable()

call f.writeline(content)
call f.close()

AssertEqual readfile(file), [content, content]


After;
call delete(file)
